package edu.neu.cloud_factory.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.neu.cloud_factory.entity.po.Device;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 设备 Mapper 接口
 * </p>
 *
 * @author halozhy
 * @since 2021-07-15
 */
@Mapper
public interface DeviceMapper extends BaseMapper<Device> {

    @Select("select * from t_device ${ew.customSqlSegment} limit #{offset}, #{limit}")
    List<Device> listPage(int offset, int limit, QueryWrapper ew);

    @Select("select * from t_device left join t_rent_rec on t_rent_rec.r_id = t_device.d_rent_rec_id " +
            "${ew.customSqlSegment} " +
            "limit #{offset}, #{limit}")
    List<Device> listPageJoinRentRec(int offset, int limit, QueryWrapper ew);

    @Select("select count(*) from t_device left join t_rent_rec on t_rent_rec.r_id = t_device.d_rent_rec_id " +
            "${ew.customSqlSegment} ")
    int listCountJoinRentRec(@Param("ew") QueryWrapper ew);

    @Select("select * from t_device left join t_rent_rec on t_rent_rec.r_id = t_device.d_rent_rec_id " +
            "${ew.customSqlSegment} ")
    List<Device> listJoinRentRec(@Param("ew") QueryWrapper ew);
}
